package com.yylany.controller;

import com.yylany.pojo.TbNews;
import com.yylany.service.NewsService;
import com.yylany.vo.NewsResult;
import com.yylany.bo.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Description: pinyougou
 *
 * @author <a href="mailto:17777502615@163.com">yaoyonglong</a>
 * @date 2018/12/19
 * @since 1.0.0
 */
@RestController
@RequestMapping
public class NewsController {
    @Autowired
    private NewsService newsService;

    /**
     * 查询网站快报
     *
     * @param pageRequest 对前台传过来的参数进行匹配查询
     * @return
     */
    @GetMapping("/news")
    public ResponseEntity<Object> findNewsByPage(PageRequest pageRequest) {
        // 1 查找当前页的新闻数据
        List<TbNews> list = newsService.findNewsByPage(pageRequest);
        // 2 查找总条数total
        int total = newsService.findTotalCount();
        // 3 组装返回结果
        NewsResult nr = new NewsResult(1, "成功", total, list);

        return ResponseEntity.ok(nr);
    }

}
